#!/usr/bin/env bash
set -ex

cd $(dirname $0)/..

source ./scripts/version.sh

./scripts/build-image-runtime

awk '{print $1}' << EOF > build/images-core.txt
    ${REGISTRY}/${REPO}/${PROG}-runtime:${DOCKERIZED_VERSION}
EOF

xargs -n1 -t docker image pull --quiet << EOF >> build/images-core.txt
    ${REGISTRY}/rancher/hardened-kubernetes:${KUBERNETES_IMAGE_TAG}
    ${REGISTRY}/rancher/hardened-coredns:v1.12.2-build20250611
    ${REGISTRY}/rancher/hardened-cluster-autoscaler:v1.10.2-build20250611
    ${REGISTRY}/rancher/hardened-dns-node-cache:1.26.0-build20250611
    ${REGISTRY}/rancher/hardened-etcd:${ETCD_VERSION}-build20250612
    ${REGISTRY}/rancher/hardened-k8s-metrics-server:v0.7.2-build20250612
    ${REGISTRY}/rancher/hardened-addon-resizer:1.8.23-build20250612
    ${REGISTRY}/rancher/klipper-helm:v0.9.7-build20250616
    ${REGISTRY}/rancher/klipper-lb:v0.4.13
    ${REGISTRY}/rancher/mirrored-pause:${PAUSE_VERSION}
    ${REGISTRY}/rancher/mirrored-ingress-nginx-kube-webhook-certgen:v1.5.3
    ${REGISTRY}/rancher/nginx-ingress-controller:v1.12.2-hardened2
    ${REGISTRY}/rancher/rke2-cloud-provider:${CCM_VERSION}
    ${REGISTRY}/rancher/mirrored-sig-storage-snapshot-controller:v8.2.0
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-traefik.txt
    ${REGISTRY}/rancher/mirrored-library-traefik:3.3.6
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-canal.txt
    ${REGISTRY}/rancher/hardened-calico:v3.30.1-build20250611
    ${REGISTRY}/rancher/hardened-flannel:v0.27.0-build20250611
EOF

if [ "${GOARCH}" != "s390x" ]; then
xargs -n1 -t docker image pull --quiet << EOF > build/images-cilium.txt
    ${REGISTRY}/rancher/mirrored-cilium-certgen:v0.2.1
    ${REGISTRY}/rancher/mirrored-cilium-cilium:v1.17.4
    ${REGISTRY}/rancher/mirrored-cilium-cilium-envoy:v1.32.6-1746661844-0f602c28cb2aa57b29078195049fb257d5b5246c
    ${REGISTRY}/rancher/mirrored-cilium-clustermesh-apiserver:v1.17.4
    ${REGISTRY}/rancher/mirrored-cilium-hubble-relay:v1.17.4
    ${REGISTRY}/rancher/mirrored-cilium-hubble-ui:v0.13.2
    ${REGISTRY}/rancher/mirrored-cilium-hubble-ui-backend:v0.13.2
    ${REGISTRY}/rancher/mirrored-cilium-operator-aws:v1.17.4
    ${REGISTRY}/rancher/mirrored-cilium-operator-azure:v1.17.4
    ${REGISTRY}/rancher/mirrored-cilium-operator-generic:v1.17.4
    ${REGISTRY}/rancher/hardened-cni-plugins:v1.7.1-build20250611
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-calico.txt
    ${REGISTRY}/rancher/mirrored-calico-operator:v1.38.1
    ${REGISTRY}/rancher/mirrored-calico-ctl:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-kube-controllers:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-typha:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-node:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-pod2daemon-flexvol:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-cni:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-apiserver:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-csi:v3.30.1
    ${REGISTRY}/rancher/mirrored-calico-node-driver-registrar:v3.30.1
EOF

if [ "${GOARCH}" != "arm64" ]; then
xargs -n1 -t docker image pull --quiet << EOF > build/images-vsphere.txt
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere:v1.33.0
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-driver:v3.3.1
    ${REGISTRY}/rancher/mirrored-cloud-provider-vsphere-csi-release-syncer:v3.3.1
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-node-driver-registrar:v2.12.0
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-resizer:v1.10.1
    ${REGISTRY}/rancher/mirrored-sig-storage-livenessprobe:v2.14.0
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-attacher:v4.7.0
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-provisioner:v4.0.1
    ${REGISTRY}/rancher/mirrored-sig-storage-csi-snapshotter:v7.0.2
EOF
fi

xargs -n1 -t docker image pull --quiet << EOF > build/images-multus.txt
    ${REGISTRY}/rancher/hardened-multus-cni:v4.2.1-build20250607
    ${REGISTRY}/rancher/hardened-cni-plugins:v1.7.1-build20250611
    ${REGISTRY}/rancher/hardened-whereabouts:v0.9.0-build20250612
    ${REGISTRY}/rancher/mirrored-library-busybox:1.36.1
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-harvester.txt
    ${REGISTRY}/rancher/harvester-cloud-provider:v0.2.4
    ${REGISTRY}/rancher/mirrored-kube-vip-kube-vip-iptables:v0.8.7
    ${REGISTRY}/rancher/harvester-csi-driver:v0.2.2
    ${REGISTRY}/rancher/mirrored-longhornio-csi-node-driver-registrar:v2.3.0
    ${REGISTRY}/rancher/mirrored-longhornio-csi-resizer:v1.2.0
    ${REGISTRY}/rancher/mirrored-longhornio-csi-provisioner:v2.1.2
    ${REGISTRY}/rancher/mirrored-longhornio-csi-attacher:v3.2.1
EOF

xargs -n1 -t docker image pull --quiet << EOF > build/images-flannel.txt
    ${REGISTRY}/rancher/hardened-flannel:v0.27.0-build20250611
    ${REGISTRY}/rancher/hardened-cni-plugins:v1.7.1-build20250611
EOF
fi
# Continue to provide a legacy airgap archive set with the default CNI images
cat build/images-core.txt build/images-canal.txt > build/images.txt
